/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.io;

import java.util.Iterator;
import java.util.Map;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

/**
 * This class wrapps a <code>MultipartHttpServletRequest</code> and allows to
 * modify the attributes and the parameters of the request without modifying the
 * underlying request.
 */
public class MultipartHttpServletRequestProxy
    extends HttpServletRequestProxy
    implements MultipartHttpServletRequest
{

  /**
   * the wrapped {@link MultipartHttpServletRequest}.
   */
  private final MultipartHttpServletRequest servletRequest;



  /**
   * constructor.
   * 
   * @param servletRequest
   *          the wrapped {@link MultipartHttpServletRequest}
   */

  MultipartHttpServletRequestProxy(MultipartHttpServletRequest servletRequest)
  {
    super(servletRequest);
    this.servletRequest = servletRequest;

  }



  /**
   * returns the contents plus description of an uploaded file in this request,
   * or <code>null</code> if it does not exist.
   * 
   * @param name
   *          a String specifying the parameter name of the multipart file
   * @return the uploaded content in the form of a MultipartFile object
   */
  public MultipartFile getFile(String name)
  {
    return servletRequest.getFile(name);
  }



  /**
   * return a Map of the multipart files contained in this request.
   * 
   * @return a map containing the parameter names as keys, and the MultipartFile
   *         objects as values
   */
  public Map<?, ?> getFileMap()
  {
    return servletRequest.getFileMap();
  }



  /**
   * return an Iterator of String objects containing the parameter names of the
   * multipart files contained in this request. These are the field names of the
   * form (like with normal parameters), not the original file names.
   * 
   * @return the names of the files
   */
  public Iterator<?> getFileNames()
  {
    return servletRequest.getFileNames();
  }

}
